package follow.juc.writing.demo3;

import java.util.concurrent.CountDownLatch;

/**
 * @Author tu zy
 * @Date 2020/12/2 17:25
 * @Version 1.0
 */
public class ThreadLocalDemo {

    private static ThreadLocal<String> threadLocal = new ThreadLocal<>();

    private String getString(){
        return threadLocal.get();
    }

    private void setString(String string){
        threadLocal.set(string);
    }

    public static void main(String[] args) {
        int threads = 9;
        ThreadLocalDemo demo = new ThreadLocalDemo();
        CountDownLatch countDownLatch = new CountDownLatch(threads);
        for (int i=0;i<threads;i++){
            new Thread(()->{
                demo.setString(Thread.currentThread().getName());
                System.out.println(demo.getString());
                countDownLatch.countDown();
            },"thread - " + i).start();
        }
    }
}
